
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_get_float_data = binder_py('mx_eyelink_get_float_data')
eyelink_get_float_data.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
eyelink_get_float_data.bindo += ['utils.o']
eyelink_get_float_data.mx_c.code = \
"""
INT16 _main( mxArray *ia[] )
{
    void FARTYPE *buf;
    INT16 code;
    code = eyelink_get_float_data( buf );
    switch ( code ) {
        mwSize t[1] = {0};
        case 0:
            *ia = mxCreateCellArray(0,t); /* Return empty array */
            break;
        case SAMPLE_TYPE:
            fsample2struct( *((FSAMPLE *) buf), ia );
            break;
        default:
            fevent2struct(*((FEVENT *) buf), ia );
            break;
    }
    return code;
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;

    /* Verify input arguments. */
    if(nrhs != 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }

    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);

    if ( nlhs == 2 ){
        *status = (double ) _main( plhs+1 );
    } else if ( nlhs < 2 ){
        void FARTYPE *buff;
        *status = (double ) eyelink_get_float_data( buff );
    }
    return;
}
"""

eyelink_get_float_data.mx_c.mdoc = \
"""function [ code, buff ] = mx_eyelink_get_float_data( )
%MX_EYELINK_GET_FLOAT_DATA Reads the last item fetched by eyelink_get_next_data()
%  into a buffer. The event is converted to a floating-point format 
% (FSAMPLE or FEVENT). This can handle both samples and events. The buffer type 
% can be ALLF_DATA for both samples and events, FSAMPLE for a sample, or a 
% specific event buffer.
%
% Parameters:
% Returns:
% 0 if no data, SAMPLE_TYPE if sample, else event type code.
% buf 	Pointer to buffer for floating-point data: type is ALLF_DATA or FSAMPLE.
%
"""
eyelink_get_float_data.write_c()
eyelink_get_float_data.write_m()
eyelink_get_float_data.compile()
eyelink_get_float_data.write_sh()

